home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-05 | 4.4 KB | 135 lines | [TEXT/PJMM] |
-
- unit Sound_Recorder;
-
- {Uses the Sound Input Device. If using Mac Recorder, the Mac Recorder Driver is necessary}
- {to properly work with the Sound Manager.}
-
- {Sys7 or Sound Manager libraries for Think Pascal is required to compile this.}
- {Build Order for Think Pascal:}
- {DRVRRunTime.lib}
- {Interface.lib}
- {ResX Utils.lib}
- {ResX Ulits.p}
- {Types.p}
- {Traps.p}
- {OSUtils.p}
- {Files.p}
- {Sound.p}
- {Dialogs.p}
- {Memory.p}
- {SoundInput.p}
- {Sound Recorder.p}
-
- {To compile in Think Pascal:}
- { 1) Set Project Type to 'Code Resource' }
- { 2) Set the File TYPE to 'RXXT' and File Creator to 'ResX'}
- { 3) Set the Resource TYPE to 'RXXT' }
- { 4) Set the Resource NAME to 'Sound Recorder'. }
- { 5) Add this file, and the above files in the build order to the project }
- { 6) Compile the code resource. }
- { 7) Install it in ResX via the 'Externals->Install' menu. }
-
- interface
- uses
- Types, OSUtils, Dialogs, Files, Sound, SoundInput, Traps, Memory, ResXUtils;
-
-
- {TheHandle is the handle that is passed in from ResX of the currently selected resource. }
- {It will not be used in this external.}
- procedure main (TheHandle: Handle);
- implementation
- procedure main;
- const
- _SoundDispatch = $A800;
- var
- myErr, hndlErr: OSErr;
- chan: SndChannelPtr;
- fileID: integer;
- warning, sTemp: Str255;
- pnt, centerPoint: point;
- Globals: GlobalsPtr;
- SndHandle: Handle;
- HType: Boolean;
-
- {Main}
- {____________________________________________________}
- begin
- SetResLoad(TRUE);
- Globals := GlobalsPtr(WindowPeek(FrontWindow)^.refCon); {From ResX Utils}
-
-
- {Make sure a file is opened within ResX before continuing.}
- if not (Globals^.LOpen) and not (Globals^.ROpen) then
- begin
- OKAlert('A file must be opened within ResX before a sound can be recorded.'); {From ResX Utils}
- exit(main);
- end;
-
- {Make sure the Sound Manager is available before continuing.}
- if not TrapAvailable(_SoundDispatch) then
- begin
- OKAlert('Sound Manager not available. This external only supports System 6.0.7, System 7.0 or higher.'); {From ResX Utils}
- exit(main);
- end;
-
-
- {Center the Sound Recorder Dialog}
- GetCenterPoint(centerPoint); {From ResX Utils}
- SetPt(pnt, centerPoint.h - 150, centerPoint.v - 40);
-
- {Get as much memory as we can. SuperNewHandle will give us 90% of the}
- {available memory if we request a ridiculously large value. Never alter HType, }
- {it is necessary to determine how to properly dispose a Super handle. See ResX}
- {Utils for information on the Super Memory Manager.}
-
- SndHandle := SuperNewHandle($FFFFFF, HType, hndlErr);
- SuperHLock(SndHandle, HType, hndlErr);
-
- {Way cool, we're ready to boogie! Let's record a sound! }
- myErr := SndRecord(nil, pnt, siGoodQuality, SndHandle); {Sound Manager or Sys7 Libraries required}
-
- if (myErr <> 0) and (SndHandle <> nil) then {Do we have a valid sound to save?}
- begin
- if (myErr <> -128) then {Maybe it was the Cancel Button?}
- begin {Display error message}
- sTemp := 'Sound Manager error: ';
- NumToString(myErr, warning);
- warning := concat(sTemp, warning);
- OKAlert(warning); {From ResX Utils}
- end;
- SuperHUnLock(SndHandle, HType, hndlErr);
- SuperDisposHandle(SndHandle, HType, hndlErr);
- end
- else {We have a valid sound to save}
- begin
- fileID := SelectFile; {From ResX Utils}
- if (fileID > 0) then {Are we saving to a file opened within ResX?}
- begin {We have a file to save it to.}
- UseResFile(fileID);
- AddResource(SndHandle, 'snd ', Unique1ID('snd '), 'Recorded Sound');
- if (ResError <> 0) then
- begin
- sTemp := 'Check disk space. Could not add the resource. Error #';
- NumToString(ResError, warning);
- warning := concat(sTemp, warning);
- OKAlert(warning); {From ResX Utils}
- SuperHUnLock(SndHandle, HType, hndlErr);
- SuperDisposHandle(SndHandle, HType, hndlErr);
- exit(main);
- end;
- WriteResource(SndHandle);
- SuperHUnLock(SndHandle, HType, hndlErr);
- ReleaseResource(SndHandle);
- end
- else {Sound was cancelled with Cancel Button}
- begin
- SuperHUnLock(SndHandle, HType, hndlErr);
- SuperDisposHandle(SndHandle, HType, hndlErr);
- end;
- end;
-
-
- {End of Sound Recorder code.}
- {____________________________________________________}
- end;
- end.